@extends('admin.base')
@section('title', '素材库')
@section('content')
    <div class="layui-card">
        <fieldset class="layui-elem-field">
            <div class="layui-field-box">
                <span class="layui-breadcrumb" lay-separator=">>">
                    <a class="layui-btn-sm" href=""
                       style="cursor:pointer;"><cite>素材视频列表</cite></a>;
                </span>
            </div>
        </fieldset>
        <div class="layui-card-header">
            <div>
                <span class="pull-left">
                  <div class="layui-form">
                    <div class="layui-form-item">
                      <div class="layui-inline">
                        <label class="layui-form-label">商品ID</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" id="sub_keywords" name="keywords"
                                   value="{{ isset($request->keywords) ? $request->keywords : '' }}" placeholder="请输入商品ID">
                        </div>
                        <label class="layui-form-label" style="width:100px;">商品不存在</label>
                        <div class="layui-input-inline" style="width:130px;">
                            <select name="sub_exit" lay-verify="required">
                                <option value="3">请选择</option>
                                <option value="1" @if($request->is_exit == 1)selected @endif>是</option>
                                <option value="2" @if($request->is_exit == 2)selected @endif>否</option>

                            </select>
                        </div>

                      </div>
                    </div>
                  </div>
                </span>
                <div class="layui-input-inline">
                    <button class="layui-btn" lay-submit lay-filter="selectsub" style="margin-top:-10px">搜索</button>
                </div>
                <span class="pull-right">
            </span>
            </div>
        </div>
        <div class="layui-tab layui-tab-card">
            <div class="layui-tab-content" style="height: 680px;">
                <div class="layui-tab-item layui-show" id="one_s">
                    <table class="layui-table" lay-even lay-size="">
                        <colgroup>
                            <col width="">
                            <col width="">
                            <col width="">
                            <col width="">
                            <col width="">
                            <col width="">
                        </colgroup>

                        <thead>
                        <tr>
                            <th class="tc">ID</th>
                            <th class="tc">商品ID</th>
                            <th class="tc">商品名称</th>
                            <th class="tc">标题</th>
                            <th class="tc">封面图</th>
                            <th class="tc">视频链接</th>
                            <th class="tc">下载量</th>
                            <th class="tc">排序</th>
                            <th class="tc">添加时间</th>
                            <th class="tc">操作</th>
                        </tr>
                        <tbody>
                        @if($list->isEmpty())
                            <tr>
                                <td colspan="10" style="text-align: center;">暂无数据</td>
                            </tr>
                        @else
                            @foreach ($list as $v)
                                <tr>
                                    <td class="tc">{{ $v->id }}</td>
                                    <td class="tc">{{ $v->gid }}</td>
                                    <td class="tc">{{ $v->gname }}</td>
                                    <td class="tc"><a title='编辑视频标题' href="javascript:void(0);"
                                                      onclick="sorts_title('{{$v->id}}','{{$v->title}}')">
                                            {{$v->title}}</a></td>
                                    {{--<td class="tc"><img src="{{$v->picname}}"></td>--}}
                                    <td class="tc" style='cursor:pointer' onclick="active('{{url('admin/source/vedio_edit_pic')}}','{{$v->id}}','编辑主图')"><img src="{{$v->picname}}" height="100px"></td>
                                    <td class="tc"><a href="{{$v->vedio}}" target="_blank">{{$v->vedio}}</a></td>
                                    <td class="tc">{{$v->click}}</td>
                                    <td class="tc"><a href="javascript:void(0);"
                                                      onclick="sorts_name('{{$v->id}}','{{$v->sort}}')">
                                            {{$v->sort}}</a></td>
                                    <td class="tc">{{$v->created_at}}</td>
                                    <td class="tc">
                                        <div class="layui-btn-group">

                                            <button class="layui-btn layui-btn-sm layui-btn-danger"
                                                    onclick="del('{{url('admin/shop/source_del')}}','{{$v->id}}');">删除
                                            </button>
                                        </div>
                                    </td>
                                </tr>
                            @endforeach
                        @endif
                        </tbody>
                        </thead>
                    </table>
                    <div class="sabrosus">{{ $page }}</div>
                </div>
            </div>
        </div>
    </div>
    </div>
@endsection

@section('js')
    <script>
        function sorts_name(id, name) {
            layer.prompt({
                formType: 3,
                value: name,
                title: '设置排列顺序'
            }, function (value, index, elem) {
                var index = layer.load();
                $.post("/admin/source/update_sort", {
                    id: id,
                    sort: value,
                    _token: "{{csrf_token()}}"
                }, function (data) {
                    layer.close(index);
                    layer.msg(data.msg);
                    if (data.code == 1) {
                        location.reload();
                    }

                })
            });
        }

        function sorts_title(id, name) {
            layer.prompt({
                formType: 2,
                value: name,
                title: '编辑视频标题'
            }, function (value, index, elem) {
                var index = layer.load();
                $.post("/admin/source/vedio_edit_title", {
                    id: id,
                    title: value,
                    _token: "{{csrf_token()}}"
                }, function (data) {
                    layer.close(index);
                    layer.msg(data.msg);
                    if (data.code == 1) {
                        location.reload();
                    }

                })
            });
        }
        layui.use('form', function(){
            var form = layui.form;
        //搜索
        form.on('submit(selectsub)', function(data){
            let keywords = $('#sub_keywords').val();//关键字
            var sub_exit = $("select[name=sub_exit]").val();
            location.href = "{{url('admin/source/index_vedio')}}"+"?keywords="+keywords+'&is_exit='+sub_exit;
            return false;
        });
        });
    </script>
@endsection